package control;

import interceptor.InjectConnection;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import utils.Var;
import utils.TextUtils;
import examinee.ExamineeInfo;
import examinee.Examinee;
import exam.*;

/**
 * Created by IntelliJ IDEA.
 * User: Shawn
 * Date: 2009-6-7
 * Time: 17:52:29
 */
public class MonitorAction {

    private Connection con;

    @InjectConnection
    public void setCon(Connection con) {
        this.con = con;
    }

    private int cid;
    private ExamineeInfo einfo;
    private TestPaperInfo tinfo;
    private List<AnswerPaperInfo> alist;

    public String monitor() throws Exception {
        ComputerInfo cinfo = Computer.getComputer(con, cid);
        einfo = Examinee.getExaminee(con, cinfo.getZkzh(), TextUtils.getToday());
        tinfo = TestPaper.getLastTestPaper(con, einfo.getEid());
        alist = AnswerPaper.getAnswerPaperList(con, tinfo.getDate(), tinfo.getTid());
        return Var.ACTION_SUCCESS;
    }

    public void setCid(int cid) {
        this.cid = cid;
    }

    public ExamineeInfo getEinfo() {
        return einfo;
    }

    public TestPaperInfo getTinfo() {
        return tinfo;
    }

    public List<AnswerPaperInfo> getAlist() {
        return alist;
    }

    private long tid;

    public String print() throws Exception {
        String path = TestPaperUtils.generate(con, tid);
        PrintThread.print(path);
        return Var.ACTION_SUCCESS;
    }

    public String setCheat() throws SQLException {
        TestPaperInfo tinfo = TestPaper.getTestPaperByTid(con, tid);
        TestPaper.setCheat(con, tinfo.getTid(), 1);
        return Var.ACTION_SUCCESS;
    }

    public String setNotCheat() throws SQLException {
        TestPaperInfo tinfo = TestPaper.getTestPaperByTid(con, tid);
        TestPaper.setCheat(con, tinfo.getTid(), 0);
        return Var.ACTION_SUCCESS;
    }

    public void setTid(long tid) {
        this.tid = tid;
    }
}
